// pages/admin-credit/admin-credit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hiddenmodalput: true,
  },
  modal_edit: function (e) {
    var id = e.currentTarget.dataset.id
    var username = e.currentTarget.dataset.username
    var credit = e.currentTarget.dataset.credit
    // console.log(id, credit)
    this.setData({
      id: id,
      username: username,
      credit: credit,
      hiddenmodalput: !this.data.hiddenmodalput
    })

  },
  cancelM: function (e) {
    this.setData({
      hiddenmodalput: true,
    })
  },

  confirmM: function (e) {
    console.log("id：" + this.data.id + "积分：" + this.data.credit);
    var that = this;
    wx.request({
      url: 'http://localhost/shopping/admin_credit_edit.php',
      header: {
        'Content-Type': 'application/json'
      },
      data: {
        id: that.data.id,
        credit: that.data.credit,
      },
      success: function (res) {
        // console.log(res.data);
        console.log("积分修改成功!")
        that.Credit();
        wx.showToast({
          title: '积分修改成功!',
          icon: 'success',
          duration: 2000
        })
        that.setData({})
      },
      fail: function (res) {
        console.log("fail");
      }
    })
    that.setData({
      hiddenmodalput: true
    })
  },
  iCredit: function (e) {
    this.setData({
      credit: e.detail.value,
    })
  },
  Credit: function () {
    var that = this
    wx.request({
      url: 'http://localhost/shopping/admin_credit.php',
      method: 'GET',
      header: {
        'Content-Type': 'application/json'
      },
      data: {},
      success: function (res) {
        // console.log(res.data)
        that.setData({
          arr: res.data.credit,
        })
      },
      fail: function (res) {
        console.log("fail");
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.Credit();
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})